/**
* @Author: zmx
* @Date: 2023/9/26
* @Description:
*/
<template>
  <el-dialog :title="title+'子类'" :visible.sync="show" append-to-body width="750px" :before-close="cancel">
    <el-form ref="formInline" :inline="true" :model="formInline" label-width="80px" :rules="rules">
      <el-row>
        <el-form-item label-width="100px" label="子类名称："  prop="assignSubName">
          <el-input v-model="formInline.assignSubName" placeholder="请输入子类名称"></el-input>
        </el-form-item>
        <el-form-item label="备注：" label-width="100px" prop="remark">
          <el-input v-model="formInline.remark" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="内容描述：" label-width="100px" prop="assignContentDesc">
          <el-input style="width: 200px" type="textarea" :rows="2" v-model="formInline.assignContentDesc" placeholder="请输入内容描述"></el-input>
        </el-form-item>
        <el-form-item label="要求描述：" label-width="100px" prop="assignDemandDesc">
          <el-input style="width: 200px" type="textarea" :rows="2"  v-model="formInline.assignDemandDesc" placeholder="请输入要求描述"></el-input>
        </el-form-item>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="checkBtn">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {userApi} from '../../api/inspection/apiUntil'
import {getSubAssignUpt} from "../../api/inspection/inspection";
export default {
  props: ['DialogAssignShow','title','row'],
  data() {
    return {
      show: false,
      rules:{
        assignSubName: [
          { required: true, message: '请输入子类名称', trigger: 'blur' }
        ],
        assignContentDesc:[
          { required: true, message: '请输入内容描述', trigger: 'blur' }
        ],
        remark:[
          { required: true, message: '请输入备注', trigger: 'blur' }
        ],
        assignDemandDesc:[
          { required: true, message: '请输入要求描述', trigger: 'blur' }
        ],
      },
      formInline: {
        assignId:'',
        assignSubName: '',
        remark:'',
        assignDemandDesc:'',
        assignContentDesc:'',
      },
    };
  },
  mounted() {
    //显示弹窗
    this.show = this.DialogAssignShow
    this.formInline.assignId = this.row.id
    if(this.title==='修改'){
      this.formInline = Object.assign(this.formInline,this.row)
    }
  },
  methods: {
    cancel(){
      this.show = false
      this.$parent.cancel()
    },
    //关闭弹窗
    handleClose() {
      this.show = false
      this.$emit('closeDialog')
    },
    getResult(res){
      if(res.code===200){
        this.$message({
          message: this.title+'成功',
          type: 'success'
        });
        this.handleClose()
      }else {
        // this.$message({
        //   message: res.msg,
        //   type: 'error'
        // });
      }
    },
    checkBtn() {
      this.$refs.formInline.validate((valid) => {
        if (valid) {
          if(this.title==='添加'){
            userApi.getSubAssignAdd(this.formInline).then((res)=>{
              this.getResult(res)
            })
          }else {
            let {isUsing,...param} = this.formInline
            userApi.getSubAssignUpt(param).then((res)=>{
              this.getResult(res)
            })
          }
        } else {
          // console.log('error submit!!');
          return false;
        }
      });

    }
  }
};
</script>

<style lang="scss" scoped>
>>> .el-dialog__header{
  padding: 20px !important;
  background: #1B7B87;
}
>>> .el-dialog__title{
  color: #fff !important;
  font-size: 16px;
}
</style>
